package br.com.dividas;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Service;


@Service
@RemotingDestination
public class Servicopagamento {
	@Autowired
	private JdbcTemplate jdbc;

	@Autowired
	private NamedParameterJdbcTemplate namParameterJdbcTemplate;
	
	
	public List getlistapagamento(int DUAM){
		return jdbc.queryForList("SELECT DUAM_IT.\"DUAM\", DUAM_IT.\"DATA_PGTO\", DUAM_IT.\"VALOR_PAGO\", DUAM_IT.\"AVISO\", DUAM_IT.\"VL_DIVIDA\", DUAM_IT.\"PARCELA\", DUAM_IT.\"DATA_VENC\" " +
				"FROM \"SCH\".\"DUAM_IT\" DUAM_IT " +
				"WHERE DUAM_IT.\"DUAM\" = "+DUAM+"");
	}
		
	public void atualizapagamento(Pagamentos pagamentos){
			String sql = "SELECT \"SCH\".manutencao_corrige_parcela(:pDUAM, :pPARCELA, :pPARCELA2)";
			
			Map<String, Object> parametros = new HashMap<String, Object>();
		parametros.put("pDUAM", 			pagamentos.DUAM);
		parametros.put("pPARCELA", 			pagamentos.PARCELA);
		parametros.put("pPARCELA2", 		pagamentos.PARCELA2);
		
		namParameterJdbcTemplate.update(sql, parametros);
	}
}
